<?php

function capacity_stats_page()
{
    global $base_url;

    $path = $base_url . "/sites/all/libraries";
    drupal_add_js(base_path().'sites/all/libraries/echarts/echarts-all.js', array('type' => 'file'));
    drupal_add_js(base_path().'sites/all/libraries/echarts/geoJson/china-main-city-map.js', array('type' => 'file'));
    drupal_add_js("var nonghuaBaseUrl = '$base_url';", array('type' => 'inline', 'scope' => 'footer'));
    drupal_add_js(base_path().'sites/all/libraries/echarts/map.js', array('type' => 'file', 'scope' => 'footer'));
    drupal_add_js(drupal_get_path('module', 'capacity') . '/js/capacity.js', array('type' => 'file', 'scope' => 'footer'));

//    $output = add_map();
//    $output .= capacity_stats_view();
    @$output= drupal_render(drupal_get_form('capacity_stats_form'));
    return $output;
}

function capacity_stats_form($form, &$form_state)
{
    $year_options=array();
    for ($i = 0; $i < 5; $i++){
        $year_options[date('Y')-$i] = date('Y')-$i;
    }
    $form['map']['#markup'] = add_map();
    $form['charts']['#markup'] = capacity_stats_view();
    $form['year'] = array(
        '#title' =>  '年份',
        '#type' => 'select',
        '#validated' => TRUE,
        '#required' => TRUE,
        '#options' => $year_options,
        '#default_value' => isset($addr_ids) ? $addr_ids->county_id : '',
    );
    $form['map_search']['#markup'] = "<input type='button' onclick='getCapacity()' value='化肥市场容量统计' class='btn btn-mini'>";
    return $form;
}
function add_map()
{
    $output = '<div id="map-wrapper-div" class="clearfix">
                    <div id="divMap" class="divMapSize"></div>
                    <input type="button" id="map_previous" value="上一级" class="btn btn-mini">
                    <input type="button" id="map_next" value="下一级" class="btn btn-mini">
               </div>';

    return $output;
}

function capacity_stats_view()
{
      // $output = '<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      //               <div class="modal-header">
      //                   <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
      //                   <h3 id="myModalLabel">化肥市场容量</h3>
      //                 </div>
      //                <div id="divcapacity" class="divPieChartSize" style="padding-bottom:20px;"></div>
      //          </div>';

       $output = '<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
               <div class="modal-dialog">
                  <div class="modal-content">
                     <div class="modal-header">
                        <button type="button" class="close" 
                           data-dismiss="modal" aria-hidden="true">
                              &times;
                        </button>
                        <h3 id="myModalLabel">化肥市场容量</h3>
                     </div>
                     <div id="divcapacity" class="divPieChartSize" style="padding-bottom:20px;"></div>
                  </div>
                </div>
            </div>';

    return $output;
}